package com.example.hyw.szysteam.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.hyw.szysteam.POJO.CLassMember;
import com.example.hyw.szysteam.R;

import java.util.ArrayList;

/**
 * Created by HYW on 2018/6/8.
 */

public class ClassMemberAdapter extends ArrayAdapter<CLassMember> implements View.OnClickListener{
    private int resource;
    private ArrayList<CLassMember> cLassMembers;

    public ClassMemberAdapter(@NonNull Context context, int resource, @NonNull ArrayList<CLassMember> cLassMembers) {
        super(context, resource, cLassMembers);
        this.resource = resource;
        this.cLassMembers = cLassMembers;
    }

    @Nullable
    @Override
    public CLassMember getItem(int position) {
        return cLassMembers.get(position);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        CLassMember cLassMember=getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null){
            view= LayoutInflater.from(getContext()).inflate(resource,null);
            viewHolder=new ViewHolder();
            viewHolder.name=view.findViewById(R.id.membername);
            viewHolder.role=view.findViewById(R.id.memberrole);
            view.setTag(viewHolder);
        }else {
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
        viewHolder.name.setText(cLassMember.getName());
        if(cLassMember.getRole()){
            viewHolder.role.setText("(老师)");
        }else {
            viewHolder.role.setText("(学生)");
        }
        return view;
    }

    @Override
    public void onClick(View view) {

    }

    class ViewHolder{
        TextView name;
        TextView role;
    }
}
